package main

import "fmt"

//4ms 47%,2.2MB 78%
func tictactoe(board []string) string {
	n := len(board)
	sumco, sumcx := 0, 0
	//遍历竖向
	for i := 0; i < n; i++ {
		co, cx := 0, 0
		for j := 0; j < n; j++ {
			if board[j][i] == 'O' {
				co++
				if co == n {
					return "O"
				}
			} else if board[j][i] == 'X' {
				cx++
				if cx == n {
					return "X"
				}
			}
		}
		sumco += co
		sumcx += cx
	}
	//遍历横向
	for i := 0; i < n; i++ {
		if board[i][0] == ' ' {
			continue
		}
		tmp := board[i][0]
		c := 0
		for j := 0; j < n; j++ {
			if board[i][j] != tmp {
				break
			}
			c++
		}
		if c == n {
			return string(tmp)
		}
	}
	//遍历对角线
	c := 0
	if board[0][0] != ' ' {
		tmp := board[0][0]
		for i := 0; i < n; i++ {
			if board[i][i] != tmp {
				break
			}
			c++
		}
	}
	if c == n {
		return string(board[0][0])
	}
	c = 0
	if board[n-1][0] != ' ' {
		tmp := board[n-1][0]
		for i := 0; i < n; i++ {
			if board[n-i-1][i] != tmp {
				break
			}
			c++
		}
	}
	if c == n {
		return string(board[n-1][0])
	}

	if sumco+sumcx == n*n {
		return "Draw"
	} else {
		return "Pending"
	}
}

func main() {
	fmt.Println(tictactoe([]string{" O    X", " O     ", "     O ", "XXXXXXX", "  O    ", " O   O ", "O  X OO"}))
}
